package com.xayoudao.uneng.util;



import android.util.SparseArray;

import com.xayoudao.uneng.BuildConfig;

/*
 * 服务器api地址的管理类
 * 根据运行的环境和模块，返回不同的api地址
 * 
 * http://yaoba.xayoudao.com/server/index.php?r=api/register   正式的
   http://yaoba.xayoudao.com/server/index-dev.php?r=api/register 开发版本的
 * 
 * http://yaoba.xayoudao.com/server/index.php?r=api/$action
 */

public class ServicesHolder {
	
	public static final int SUBAREA = 1 ;
	public static final int GET_EVENTS = 2 ;
	public static final int GET_TICKETS = 3 ;
	public static final int SHAKEINFO_TOSERVER = 4 ;
	public static final int SUBMIT_VOTE = 5 ;
	public static final int GET_UPDSTE_INFO = 6 ;
	

	public static int DEBUGE = 0;
	public static int RELEASE = 1;
//	public static int TEST = 2;
	static int environment = 1;
	public static SparseArray<String> env;
	public static SparseArray<String> mapmodule = null;

	static {
		
		env = new SparseArray<String>();

		//env.put(DEVELOPMENT, "http://cloud.appmars.com");
		env.put(DEBUGE, "http://emap.appmars.com/server/index.php?r=api");
		env.put(RELEASE, "http://emap.appmars.com/server/index.php?r=api") ;
		// env.put(TEST, "http://test.ent.appmars.com");

		mapmodule = new SparseArray<String>();

		mapmodule.put(SUBAREA, "/subarea");
		mapmodule.put(GET_EVENTS, "/events");
		mapmodule.put(GET_TICKETS, "/tickets");
		mapmodule.put(SHAKEINFO_TOSERVER, "/shake");
		mapmodule.put(SUBMIT_VOTE, "/vote");
		mapmodule.put(GET_UPDSTE_INFO, "/version") ;

	}

	/*
	 * environment决定返回那个服务器 module决定返回那个模块
	 */
	public static String api(int module) {
		String path;
//		Log.d("BuildConfig.DEBUG", BuildConfig.DEBUG+"");
		if(BuildConfig.DEBUG){
			path = env.get(DEBUGE) + mapmodule.get(module);	
//			Log.d("DEBUGE path", path);
		}else{
			path = env.get(RELEASE) + mapmodule.get(module);
//			Log.d(" RELEASE path", path);
		}
		
//		path = env.get(RELEASE) +mapmodule.get(module);
		//Toast.makeText(context, "ddd:"+path, 0).show() ;
//		Log.d("path", path);
		return path;
	}

 

	public static void setEnvironment(int env) {
		environment = env;
	}
}
